/**  
 * Copyright (c) 2008, Noel Lynch All rights reserved. Redistribution and use  
 * in source and binary forms, with or without modification, are permitted  
 * provided that the following conditions are met: Redistributions of source  
 * code must retain the above copyright notice, this list of conditions and the  
 * following disclaimer. Redistributions in binary form must reproduce the above  
 * copyright notice, this list of conditions and the following disclaimer in the  
 * documentation and/or other materials provided with the distribution. Neither  
 * the name of Noel Lynch nor the names of contributors may be used to  
 * endorse or promote products derived from this software without specific prior  
 * written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A  
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR  
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR  
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF  
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
 */
// Jul 29, 2008

package com.sceneworker.monitorpopup.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;

import com.jme2utils.importers.DAEImport;
import com.jme2utils.importers.FormatConverterImportCallback;
import com.jme2utils.importers.JMEImport;
import com.jme2utils.importers.OgreImport;
import com.jme2utils.staticutils.ModelUtils;
import com.jme2utils.staticutils.ModelUtils.HandleImportedObjectCallback;
import com.jme2utils.staticutils.ModelUtils.IImportFile;
import com.jmex.model.converters.AseToJme;
import com.jmex.model.converters.MaxToJme;
import com.jmex.model.converters.Md2ToJme;
import com.jmex.model.converters.Md3ToJme;
import com.jmex.model.converters.MilkToJme;
import com.jmex.model.converters.ObjToJme;
import com.jmex.model.converters.X3dToJme;
import com.myjavautils.swing.MigLayoutUtils;
import com.myjavautils.swing.SimpleAlert;
import com.myjavautils.swing.SwingComponentFactory;
import com.sceneworker.monitorpopup.panels.importers.MD5Import;

public class SingleFileImportPanel extends JPanel{

	private static final String IMPORT_JME = "Import JME";
	private static final String IMPORT_ORGE_MESH_XML_FORMAT = "Import Orge Mesh XML format";
	private static final String IMPORT_MD5 = "Import MD5";
	private static final String IMPORT_ASE = "Import ASE";
	private static final String IMPORT_X3D = "Import X3D";
	private static final String IMPORT_MS3D = "Import MS3D";
	private static final String IMPORT_MD3 = "Import MD3";
	private static final String IMPORT_MD2 = "Import MD2";
	private static final String IMPORT_DAE = "Import DAE";
	private static final String IMPORT_OBJ = "Import OBJ";
	private static final String IMPORT_3DS = "Import 3DS";

	private		Object		mcl_parentObject;
	
	static	private		boolean		mb_md5ImporterAdded = false;
	
	public	SingleFileImportPanel(Object cl_main) {
		MigLayoutUtils.asMigLayout(this);

		if(!mb_md5ImporterAdded) {
			ModelUtils.addImporter("md5", new MD5Import());
			mb_md5ImporterAdded = true;
		}
		
		mcl_parentObject = cl_main;
		buildModelImportUI();
	}
	
	public	Object		getParentObject() {
		return mcl_parentObject;
	}
	
	private	void	buildModelImportUI() {
		final	JComboBox		lcl_comboBox = SwingComponentFactory.makeAComboBox();
		add(lcl_comboBox);
		
		DefaultComboBoxModel		lcl_model = new DefaultComboBoxModel();

		Enumeration<String>		lstra_keys = ModelUtils.getImporters().keys();

		while(lstra_keys.hasMoreElements()) {
			String		lstr_key = lstra_keys.nextElement();
			lcl_model.addElement(lstr_key);
		}

		lcl_comboBox.setModel(lcl_model);
		
		final	SingleFileImportPanel		lcl_this = this;
		
		JButton		lcl_btn = SwingComponentFactory.makeAButton("Import");
		add(lcl_btn);
		lcl_btn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				IImportFile		lcl_callback = ModelUtils.getImporters().get(lcl_comboBox.getSelectedItem());
				if(!lcl_callback.doImportUI(mcl_parentObject)) {
					SimpleAlert.doAlert("Import failed", lcl_this);
				}
			}

		});
	}	
}
